using GameFrameWork.Editor;
using UnityEditor;
using UnityEngine;
using static GameFrameWork.Constant;

namespace GameFrameWork.Editor
{
    public partial class ScriptGenerator
    {

        // NetworkRequest
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "NetworkRequest", priority = 0)]
        public static void CreateNetworkRequestScript()
        {
            CreateScript("NetworkRequest");
        }

        // Manager
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "Manager", priority = 1)]
        public static void CreateManagerScript()
        {
            CreateScript("Manager");
        }

        // TableManager
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "TableManager", priority = 1)]
        public static void CreateTableManagerScript()
        {
            CreateScript("Manager", false, EditorSetting.EditorMenu.ScriptTemplateDirectory + "/" + "TableManagerTemplate.txt");
        }

        // EventArgs
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "EventArgs", priority = 20)]
        public static void CreateEventArgsScript()
        {
            CreateScript("EventArgs");
        }

        // OpenParams
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "OpenParams", priority = 21)]
        public static void CreateOpenPramsScript()
        {
            CreateScript("OpenParams");
        }

        // ConditionData
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "ConditionData", priority = 22)]
        public static void CreateConditionDataScript()
        {
            CreateScript("ConditionData", true);
        }

        // Enums
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "Enums", priority = 40)]
        public static void CreateEnumsScript()
        {
            CreateScript("Enums", true);
        }

        // Constant
        [MenuItem(EditorSetting.EditorMenu.MenuDiretoryPrefix + "Constant", priority = 41)]
        public static void CreateConstantScript()
        {
            CreateScript("Constant", true);
        }

        static void CreateScript(string className, bool multi = false, string tmpPath = "")
        {
            UnityEngine.Object activeObject = Selection.activeObject;
            string generatedPath = AssetDatabase.GetAssetPath(activeObject);

            string filePath;
            if (multi)
            {
                filePath = generatedPath + "/" + className + ".New.cs";
            }
            else
            {
                filePath = generatedPath + "/New" + className + ".cs";
            }

            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0,
                ScriptableObject.CreateInstance<GenerateScriptsAction>(),
                filePath,
                null, tmpPath.Equals(string.Empty) ? EditorSetting.EditorMenu.ScriptTemplateDirectory + "/" + className + "Template.txt" : tmpPath);
        }
    }
}


